package xyz.robinbingo.leetcode.a20.b05.c30;

public class Solution {
    public int largestRectangleArea(int[] heights) {
        int length = heights.length;
        int result = 0;
        for (int i = 0; i < length; i++) {
            int height = heights[i];
            int width = 0;
            for (int j = i; j < length; j++) {
                if (heights[j] >= height) {
                    width++;
                } else {
                    break;
                }
            }
            for (int j = i - 1; j >= 0; j--) {
                if (heights[j] >= height) {
                    width++;
                } else {
                    break;
                }
            }
            result = Math.max(height * width, result);
        }
        return result;
    }
}